<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //async函数返回的是一个promise对象，相当于promise.then()

        async function fn() {
            //即使返回的是字符串，async函数返回值也是promise对象
            return 'sgg'
        }

        console.log(fn()) //promise状态为成功，值为sgg

        async function fn2() {
             //只要这里返回结果不是promise对象，async函数真正的返回结果就是成功的promise对象
             return;
        }
        console.log(fn2()) //promise状态为成功，值为undefined

        async function fn3() {
             //如果抛出错误，则返回结果是失败的promise
             throw new Error('出错了');
        }
        console.log(fn3()) //promise状态为失败，值为Error对象

        async function fn4() {
             //如果返回promise对象，则async返回值的promise状态与此处一致
             return new Promise((resolve, reject)=>{
                resolve('成功');
                //reject('失败了.')
             });
        }
        let res = fn4()
        console.log(fn4()) //promise状态为成功，值为data
        res.then(value=>{
            console.log(value)
        }).catch(reason=>{
            console.warn(reason)
        })

    </script>
</body>
</html>